using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EngineGame;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
namespace WarsOnRiceFields
{
    /// <summary>
    /// Lop nay quan ly menu
    /// </summary>
    class Menu:GameScreen
    {
        Sprite bgrSprite;
        public List<MenuEntry> MenuEntries = new List<MenuEntry>();
         public Menu()
            
        {
            // Create our menu entries.
            MenuEntry startMenuEntry = new MenuEntry("New Game",new Vector2(550,35));
            MenuEntry scoreMenuEntry = new MenuEntry("Continue", new Vector2(580, 110));
            MenuEntry aboutMenuEntry = new MenuEntry("About Us", new Vector2(590, 180));
            MenuEntry exitMenuEntry = new MenuEntry("Quit", new Vector2(610, 260));

            // Hook up menu event handlers.
            startMenuEntry.Selected += StartMenuEntrySelected;
            scoreMenuEntry.Selected+= ScoreMenuEntrySelected;
            exitMenuEntry.Selected += ExitGame;
            
            // Add entries to the menu.
            MenuEntries.Add(startMenuEntry);
            MenuEntries.Add(scoreMenuEntry);
            MenuEntries.Add(aboutMenuEntry);
            MenuEntries.Add(exitMenuEntry);

        }
        public override void LoadContent()
        {
            bgrSprite = new Sprite(ScreenManager.Game.Content, "Images/menu");
            base.LoadContent();
        }
        void StartMenuEntrySelected(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new Introduction());
            ScreenManager.RemoveScreen(this);
        }
        void ScoreMenuEntrySelected(object sender,EventArgs e)
        {
        //    ScreenManager.AddScreen(new HighScore(HighScoreAction.Load));
            ScreenManager.RemoveScreen(this);
        }
        void ExitGame(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
           bgrSprite.Draw(ScreenManager.SpriteBatch);
           if (MenuEntries.Count > 0)
           {
               
               SpriteFont font = ScreenManager.Font;


               // Draw each menu entry in turn.
               foreach (MenuEntry menuEntry in MenuEntries)
               {
                   menuEntry.Draw(ScreenManager.SpriteBatch,font);
               }

              
           }
            ScreenManager.SpriteBatch.End();
            base.Draw(gameTime);
        }
        public override void HandleInput(InputState input)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (input.PauseGame)
            {
                ScreenManager.Game.Exit();
            }
            TouchCollection touchState = TouchPanel.GetState();
            if (touchState.Count > 0)
            {
                foreach (MenuEntry menuEntry in MenuEntries)
                {
                    menuEntry.OnSelectEntry(touchState[0]);
                }
            }
        }
     
    }
}
